<?php

namespace app\admin\model\order;

use think\Model;


class Gold extends Model
{





    // 表名
    protected $name = 'order';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'ontime_text',
        'paytime_text',
        'overtime_text'
    ];






    public function getOntimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ontime']) ? $data['ontime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPaytimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getOvertimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['overtime']) ? $data['overtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setOntimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPaytimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setOvertimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function goods()
    {
        return $this->belongsTo('app\admin\model\goods\Goods', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function personal()
    {
        return $this->belongsTo('app\admin\model\personal\Personal', 'uid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function admin()
    {
        return $this->belongsTo('app\admin\model\admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function getStatusList()
    {
        return ['1' => '待支付','4' => '挂单', '2' => '待发货','3' => '已发货','5' => '已完成','7' => '已撤单','9'=>'取消订单'];
    }
}
